package com.ruoyi.supervise.service.impl.decisupport;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.supervise.config.CityConfig;
import com.ruoyi.supervise.domain.decisupport.City;
import com.ruoyi.supervise.domain.decisupport.MunicipalEngineering;
import com.ruoyi.supervise.mapper.decisupport.MunicipalEngineeringMapper;
import com.ruoyi.supervise.service.decisupport.MunicipalEngineeringService;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;

@Service
@DataSource(value = DataSourceType.SLAVE)
public class MunicipalEngineeringServiceImpl implements MunicipalEngineeringService{

    @Autowired
    private MunicipalEngineeringMapper municipalEngineeringMapper;
    
    @Autowired
    private CityConfig cityConfig;

	@Override
	public List<MunicipalEngineering> selectAllProME(MunicipalEngineering me) {
		// TODO Auto-generated method stub
		return municipalEngineeringMapper.selectAllProME(me);
	}

	@Override
	public MunicipalEngineering selectAllProMEProvince(MunicipalEngineering me) {
		// TODO Auto-generated method stub
		return municipalEngineeringMapper.selectAllProMEProvince(me);
	}

	@Override
	public List<MunicipalEngineering> selectAllProMETbale(MunicipalEngineering me) {
		List<MunicipalEngineering> apMETable=municipalEngineeringMapper.selectAllProME(me);
		List<MunicipalEngineering> allME=new ArrayList<MunicipalEngineering>();
		for(City c:cityConfig.getCityList())
		{
			MunicipalEngineering m=new MunicipalEngineering();
			m.setProjectCityNum(c.getCityname());
			m.setTotalNum("0");
			m.setComparedTotalNum("0");
			m.setTotalMoney("0");
			m.setComparedTotalMoney("0");
			allME.add(m);
		}
		for(MunicipalEngineering allMETbale:allME)
		{
			if(apMETable!=null) {
				for(MunicipalEngineering apMETableData:apMETable)
				{
					if(StrUtil.isNotBlank(apMETableData.getProjectCityNum()) && allMETbale.getProjectCityNum().equals(apMETableData.getProjectCityNum()))
					{
						allMETbale.setTotalNum(apMETableData.getTotalNum());
						allMETbale.setComparedTotalNum(apMETableData.getComparedTotalNum());
						allMETbale.setTotalMoney(apMETableData.getTotalMoney());
						allMETbale.setComparedTotalMoney(apMETableData.getComparedTotalMoney());
					}
				}
			}
		}
		return allME;
	}

	@Override
	public int countFJMoneyInOneKW(MunicipalEngineering me) {
		// TODO Auto-generated method stub
		return municipalEngineeringMapper.countFJMoneyInOneKW(me);
	}

	@Override
	public int countFJMoneyOneKWToFiveKW(MunicipalEngineering me) {
		// TODO Auto-generated method stub
		return municipalEngineeringMapper.countFJMoneyOneKWToFiveKW(me);
	}

	@Override
	public int countFJMoneyFiveKWToOneB(MunicipalEngineering me) {
		// TODO Auto-generated method stub
		return municipalEngineeringMapper.countFJMoneyFiveKWToOneB(me);
	}

	@Override
	public int countFJMoneyOneBToFiveB(MunicipalEngineering me) {
		// TODO Auto-generated method stub
		return municipalEngineeringMapper.countFJMoneyOneBToFiveB(me);
	}

	@Override
	public int countFJMoneyUpFiveB(MunicipalEngineering me) {
		// TODO Auto-generated method stub
		return municipalEngineeringMapper.countFJMoneyUpFiveB(me);
	}

	@Override
	public List<MunicipalEngineering> selectAllNumME(MunicipalEngineering me) {
		// TODO Auto-generated method stub
		return municipalEngineeringMapper.selectAllNumME(me);
	}

	@Override
	public List<MunicipalEngineering> selectAllNumMERLT(MunicipalEngineering me) {
		List<MunicipalEngineering> allMENum=municipalEngineeringMapper.selectAllNumME(me);
		List<MunicipalEngineering> allMENumData=new ArrayList<MunicipalEngineering>();
		for(City c:cityConfig.getCityList())
		{
			MunicipalEngineering m=new MunicipalEngineering();
			m.setProjectCityNum(c.getCityname());
			m.setTotalNum("0");
			allMENumData.add(m);
		}
		for(MunicipalEngineering med:allMENumData)
		{
			for(MunicipalEngineering m:allMENum)
			{
				if(med.getProjectCityNum().equals(m.getProjectCityNum()))
				{
					med.setTotalNum(m.getTotalNum());
				}
			}
		}
		return allMENumData;
	}

}
